//
//  RBRegisterSetPasswordVC.m
//  zhongzhenglu
//
//  Created by XL on 2022/7/5.
//

#import "RBRegisterSetPasswordVC.h"
#import "RBDefine.h"
#import "RBNavigationBar.h"
#import "UIView+RBAdd.h"
#import <UINavigationController+FDFullscreenPopGesture.h>
#import <Masonry.h>
#import "RBGradientView.h"
#import <UIColor+YYAdd.h>
#import <UIView+YYAdd.h>
#import "RBLoginRuleView.h"
#import "RBTextField.h"
#import "UIViewController+RBAdd.h"

@interface RBRegisterSetPasswordVC ()

@property(nonatomic, strong)RBGradientView *bgView;
@property(nonatomic, strong)RBNavigationBar *navigationBar;
@property(nonatomic, strong)IBOutlet UIView *topView;
@property(nonatomic, strong)IBOutlet RBTextField *passwordF;

@end

@implementation RBRegisterSetPasswordVC

#pragma mark - Lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setup];
}

#pragma mark - Private

- (void)setup
{
    self.fd_prefersNavigationBarHidden = YES;
    self.view.backgroundColor = UIColor.whiteColor;
    self.bgView.hidden = NO;
    self.navigationBar.hidden = NO;
    
    self.passwordF.type = RBTextFieldTypePasswordSecurity;
    
    [self.topView zoomSubViewsWithSelf];
    self.topView.height = Zoom(self.topView.height);
    [self.view addSubview:self.topView];
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(self.navigationBar.mas_bottom).offset(Zoom(50));
        make.height.mas_equalTo(self.topView.height);
    }];

}

#pragma mark - Network

#pragma mark - Event

- (IBAction)confirmBtnTapped:(id)sender
{
    if (!self.passwordF.validate)
    {
        [self.view showTip:@"密码格式不符合要求" completion:nil];
        return;
    }
    __weak typeof(self) weak_self = self;
    [self viewLoadDataWithParam:^(NSMutableDictionary *dicM) {
        dicM[@"user_id"] = self.loginResponse.data.user_id;
        dicM[@"pwd"] = self.passwordF.text;
    } path:@"han_pwd_add" post:YES log:YES responseClass:RBResponse.class desView:self.view showHud:YES showPlaceHolder:NO sucBlock:^(id data) {
        weak_self.loginResponse.data.is_setpwd = NO;
        if(weak_self.passwordSetBlock)
        {
            weak_self.passwordSetBlock(weak_self.loginResponse);
        }
    } failBlock:^(RBResponse *data) {
        [weak_self.view showTip:data.message completion:nil];
    } reloadBlock:nil];
}

#pragma mark - Setter

#pragma mark - Getter

- (RBGradientView *)bgView
{
    if (!_bgView)
    {
        self.bgView = ({
            RBGradientView *view = [RBGradientView gradientViewWithColors:@[[UIColor colorWithHexString:@"#CADCFF"], [UIColor colorWithHexString:@"#ffffff"]] locations:@[@0, @1] vertical:YES];
            [self.view addSubview:view];
            [view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.top.right.mas_equalTo(0);
                make.height.mas_equalTo(595);
            }];
            view;
        });
    }
    return _bgView;
}

- (RBNavigationBar *)navigationBar
{
    if (!_navigationBar)
    {
        self.navigationBar = ({
            RBNavigationBar *bar = RBNavigationBar.new;
            bar.needGradientView = NO;
            [self.view addSubview:bar];
            [bar mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.top.right.mas_equalTo(0);
                make.height.mas_equalTo(kRBStatusBarHeight + kRBNavigationBarHeight);
            }];
            [bar.naviBar addBackBtnWithWidth:70 image:[UIImage imageNamed:@"backBlack"]];
            bar;
        });
    }
    return _navigationBar;
}

@end
